<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户编号" prop="custNo">
        <el-input
          v-model="queryParams.custNo"
          placeholder="请输入客户编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作类别" prop="actionType">
        <el-input
          v-model="queryParams.actionType"
          placeholder="请输入操作类别"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关联信息" prop="actionKey">
        <el-input
          v-model="queryParams.actionKey"
          placeholder="请输入关联信息"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机品牌" prop="phoneBrand">
        <el-input
          v-model="queryParams.phoneBrand"
          placeholder="请输入手机品牌"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机型号" prop="phoneModel">
        <el-input
          v-model="queryParams.phoneModel"
          placeholder="请输入手机型号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机最大内存" prop="maxMemory">
        <el-input
          v-model="queryParams.maxMemory"
          placeholder="请输入手机最大内存"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前运营商" prop="phoneOperators">
        <el-input
          v-model="queryParams.phoneOperators"
          placeholder="请输入当前运营商"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否有sim卡" prop="hasSimCard">
        <el-input
          v-model="queryParams.hasSimCard"
          placeholder="请输入是否有sim卡"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="imei" prop="imei">
        <el-input
          v-model="queryParams.imei"
          placeholder="请输入imei"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="sn" prop="sn">
        <el-input
          v-model="queryParams.sn"
          placeholder="请输入sn"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否root" prop="hasRoot">
        <el-input
          v-model="queryParams.hasRoot"
          placeholder="请输入是否root"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备指纹" prop="fingerprint">
        <el-input
          v-model="queryParams.fingerprint"
          placeholder="请输入设备指纹"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="ip地址" prop="ipAddress">
        <el-input
          v-model="queryParams.ipAddress"
          placeholder="请输入ip地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="mac地址" prop="mac">
        <el-input
          v-model="queryParams.mac"
          placeholder="请输入mac地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国家" prop="country">
        <el-input
          v-model="queryParams.country"
          placeholder="请输入国家"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="州" prop="countryState">
        <el-input
          v-model="queryParams.countryState"
          placeholder="请输入州"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入城市"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地区" prop="region">
        <el-input
          v-model="queryParams.region"
          placeholder="请输入地区"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in stateOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['app:AppDeviceInfo:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['app:AppDeviceInfo:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['app:AppDeviceInfo:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['app:AppDeviceInfo:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="AppDeviceInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" align="center" prop="id"/>
      <el-table-column label="用户id" align="center" prop="userId"/>
      <el-table-column label="客户编号" align="center" prop="custNo"/>
      <el-table-column label="操作类别" align="center" prop="actionType"/>
      <el-table-column label="关联信息" align="center" prop="actionKey"/>
      <el-table-column label="手机品牌" align="center" prop="phoneBrand"/>
      <el-table-column label="手机型号" align="center" prop="phoneModel"/>
      <el-table-column label="手机开机时间" align="center" prop="startupTime"/>
      <el-table-column label="手机充电次数" align="center" prop="chargeCount"/>
      <el-table-column label="手机当前电量" align="center" prop="quantityOfElectricity"/>
      <el-table-column label="手机陀螺仪参数" align="center" prop="gyroscopeParameters"/>
      <el-table-column label="手机最大内存" align="center" prop="maxMemory"/>
      <el-table-column label="手机已用内存" align="center" prop="useMemory"/>
      <el-table-column label="当前运营商" align="center" prop="phoneOperators"/>
      <el-table-column label="是否有sim卡" align="center" prop="hasSimCard"/>
      <el-table-column label="经度" align="center" prop="longitude"/>
      <el-table-column label="纬度" align="center" prop="latitude"/>
      <el-table-column label="imei" align="center" prop="imei"/>
      <el-table-column label="sn" align="center" prop="sn"/>
      <el-table-column label="是否root" align="center" prop="hasRoot"/>
      <el-table-column label="设备指纹" align="center" prop="fingerprint"/>
      <el-table-column label="ip地址" align="center" prop="ipAddress"/>
      <el-table-column label="mac地址" align="center" prop="mac"/>
      <el-table-column label="国家" align="center" prop="country"/>
      <el-table-column label="州" align="center" prop="countryState"/>
      <el-table-column label="城市" align="center" prop="city"/>
      <el-table-column label="地区" align="center" prop="region"/>
      <el-table-column label="地址" align="center" prop="address"/>
      <el-table-column label="wifi名称" align="center" prop="wifiName"/>
      <el-table-column label="状态" align="center" prop="state" :formatter="stateFormat"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['app:AppDeviceInfo:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['app:AppDeviceInfo:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户设备信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id"/>
        </el-form-item>
        <el-form-item label="客户编号" prop="custNo">
          <el-input v-model="form.custNo" placeholder="请输入客户编号"/>
        </el-form-item>
        <el-form-item label="操作类别" prop="actionType">
          <el-input v-model="form.actionType" placeholder="请输入操作类别"/>
        </el-form-item>
        <el-form-item label="关联信息" prop="actionKey">
          <el-input v-model="form.actionKey" placeholder="请输入关联信息"/>
        </el-form-item>
        <el-form-item label="手机品牌" prop="phoneBrand">
          <el-input v-model="form.phoneBrand" placeholder="请输入手机品牌"/>
        </el-form-item>
        <el-form-item label="手机型号" prop="phoneModel">
          <el-input v-model="form.phoneModel" placeholder="请输入手机型号"/>
        </el-form-item>
        <el-form-item label="手机开机时间" prop="startupTime">
          <el-input v-model="form.startupTime" placeholder="请输入手机开机时间"/>
        </el-form-item>
        <el-form-item label="手机充电次数" prop="chargeCount">
          <el-input v-model="form.chargeCount" placeholder="请输入手机充电次数"/>
        </el-form-item>
        <el-form-item label="手机当前电量" prop="quantityOfElectricity">
          <el-input v-model="form.quantityOfElectricity" placeholder="请输入手机当前电量"/>
        </el-form-item>
        <el-form-item label="手机陀螺仪参数" prop="gyroscopeParameters">
          <el-input v-model="form.gyroscopeParameters" placeholder="请输入手机陀螺仪参数"/>
        </el-form-item>
        <el-form-item label="手机最大内存" prop="maxMemory">
          <el-input v-model="form.maxMemory" placeholder="请输入手机最大内存"/>
        </el-form-item>
        <el-form-item label="手机已用内存" prop="useMemory">
          <el-input v-model="form.useMemory" placeholder="请输入手机已用内存"/>
        </el-form-item>
        <el-form-item label="当前运营商" prop="phoneOperators">
          <el-input v-model="form.phoneOperators" placeholder="请输入当前运营商"/>
        </el-form-item>
        <el-form-item label="是否有sim卡" prop="hasSimCard">
          <el-input v-model="form.hasSimCard" placeholder="请输入是否有sim卡"/>
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度"/>
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度"/>
        </el-form-item>
        <el-form-item label="imei" prop="imei">
          <el-input v-model="form.imei" placeholder="请输入imei"/>
        </el-form-item>
        <el-form-item label="sn" prop="sn">
          <el-input v-model="form.sn" placeholder="请输入sn"/>
        </el-form-item>
        <el-form-item label="是否root" prop="hasRoot">
          <el-input v-model="form.hasRoot" placeholder="请输入是否root"/>
        </el-form-item>
        <el-form-item label="设备指纹" prop="fingerprint">
          <el-input v-model="form.fingerprint" placeholder="请输入设备指纹"/>
        </el-form-item>
        <el-form-item label="ip地址" prop="ipAddress">
          <el-input v-model="form.ipAddress" placeholder="请输入ip地址"/>
        </el-form-item>
        <el-form-item label="mac地址" prop="mac">
          <el-input v-model="form.mac" placeholder="请输入mac地址"/>
        </el-form-item>
        <el-form-item label="国家" prop="country">
          <el-input v-model="form.country" placeholder="请输入国家"/>
        </el-form-item>
        <el-form-item label="州" prop="countryState">
          <el-input v-model="form.countryState" placeholder="请输入州"/>
        </el-form-item>
        <el-form-item label="城市" prop="city">
          <el-input v-model="form.city" placeholder="请输入城市"/>
        </el-form-item>
        <el-form-item label="地区" prop="region">
          <el-input v-model="form.region" placeholder="请输入地区"/>
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址"/>
        </el-form-item>
        <el-form-item label="wifi名称" prop="wifiName">
          <el-input v-model="form.wifiName" placeholder="请输入wifi名称"/>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-select v-model="form.state" placeholder="请选择状态">
            <el-option
              v-for="dict in stateOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listAppDeviceInfo, getAppDeviceInfo, delAppDeviceInfo, addAppDeviceInfo, updateAppDeviceInfo, exportAppDeviceInfo} from "@/api/app/AppDeviceInfo";

export default {
  name: "AppDeviceInfo",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户设备信息表格数据
      AppDeviceInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态字典
      stateOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        custNo: null,
        actionType: null,
        actionKey: null,
        phoneBrand: null,
        phoneModel: null,
        maxMemory: null,
        phoneOperators: null,
        hasSimCard: null,
        imei: null,
        sn: null,
        hasRoot: null,
        fingerprint: null,
        ipAddress: null,
        mac: null,
        country: null,
        countryState: null,
        city: null,
        region: null,
        state: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          {required: true, message: "用户id不能为空", trigger: "blur"}
        ],
        actionType: [
          {required: true, message: "操作类别不能为空", trigger: "blur"}
        ],
        createTime: [
          {required: true, message: "创建时间不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    // this.getList();
    this.getDicts("sys_common_status").then(response => {
      this.stateOptions = response.data;
    });
  },
  methods: {
    /** 查询用户设备信息列表 */
    getList() {
      this.loading = true;
      listAppDeviceInfo(this.queryParams).then(response => {
        this.AppDeviceInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 状态字典翻译
    stateFormat(row, column) {
      return this.selectDictLabel(this.stateOptions, row.state);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        custNo: null,
        actionType: null,
        actionKey: null,
        phoneBrand: null,
        phoneModel: null,
        startupTime: null,
        chargeCount: null,
        quantityOfElectricity: null,
        gyroscopeParameters: null,
        maxMemory: null,
        useMemory: null,
        phoneOperators: null,
        hasSimCard: null,
        longitude: null,
        latitude: null,
        imei: null,
        sn: null,
        hasRoot: null,
        fingerprint: null,
        ipAddress: null,
        mac: null,
        country: null,
        countryState: null,
        city: null,
        region: null,
        address: null,
        wifiName: null,
        createTime: null,
        state: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户设备信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAppDeviceInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户设备信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAppDeviceInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAppDeviceInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除用户设备信息编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delAppDeviceInfo(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有用户设备信息数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportAppDeviceInfo(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
